package com.bclz.netty.websocket;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
import io.netty.util.CharsetUtil;


public class WebSocketHandler extends SimpleChannelInboundHandler<WebSocketFrame> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame msg) throws Exception {
        System.out.println("接受消息:");
        System.out.println(msg.content().toString(CharsetUtil.UTF_8));
        ctx.channel().writeAndFlush(new TextWebSocketFrame(Unpooled.copiedBuffer("可以的", CharsetUtil.UTF_8)));
    }


}
